﻿namespace MvvmTools.NotifyPropertyChanged
{
    using System;
    using System.Diagnostics;
    using System.Diagnostics.Contracts;
    using System.Linq.Expressions;
    using JetBrains.Annotations;

    [DebuggerDisplay("{Name} : {typeof(TProperty)}")]
    internal sealed class Accessor<TParent, TProperty>
    {
        public Accessor([NotNull] string name, [NotNull] Expression<Func<TParent, TProperty>> propertySelector)
        {
            Contract.Requires<ArgumentNullException>(name != null);
            Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(name));
            Contract.Requires<ArgumentNullException>(propertySelector != null);

            Name = name;
            Getter = propertySelector.Compile();
        }

        public string Name { [NotNull] get; private set; }

        public Func<TParent, TProperty> Getter { [NotNull] get; private set; }
    }
}
